package jp.eisbahn.mgapi.api.photo;

import java.text.ParseException;
import java.util.Date;

import jp.eisbahn.mgapi.api.Model;
import jp.eisbahn.mgapi.api.User;
import jp.eisbahn.mgapi.util.DateUtils;

import org.json.simple.JSONObject;

/**
 * This model class has information about a comment posted to a photo.
 * @author Yoichiro Tanaka
 */
public class Comment extends Model {

    /** The user object. */
    private User user;

    /**
     * Initialize this instance.
     * @param newOriginal The JSON object.
     */
    protected Comment(final JSONObject newOriginal) {
        super(newOriginal);
        user = new User(getPropertyJSONObject("user"));
    }

    /**
     * Retrieve the ID.
     * @return The ID string.
     */
    public final String getId() {
        return getPropertyString("id");
    }

    /**
     * Retrieve the createAt property value.
     * @return The createAt value as Date object.
     * @throws ParseException If the parsing operation is failed.
     */
    public final Date getCreatedAt() throws ParseException {
        String createdAt = getPropertyString("created");
        if (createdAt != null) {
            return DateUtils.convertDate(createdAt);
        } else {
            return null;
        }
    }

    /**
     * Retrieve the text.
     * @return The text string.
     */
    public final String getText() {
        return getPropertyString("text");
    }

    /**
     * Retrieve the userr object.
     * @return The user object.
     */
    public final User getUser() {
        return user;
    }

}
